package terminals;


import javax.microedition.lcdui.Display;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

import connectionSettings.SocketConnectionSettings;



public class SocketTerminal extends MIDlet {
	
	public SocketConnectionSettings myForm;

	protected void startApp() throws MIDletStateChangeException {

		myForm = new SocketConnectionSettings(Display.getDisplay(this));
	}
	


	protected void pauseApp() {

	}

	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
	
	}
	/*Connection myConnection;
	TerminalForm myTerminalForm;
	

	protected void startApp() throws MIDletStateChangeException {
	 initTerminal();
			}
	
	public void initTerminal(){
		myTerminalForm = new TerminalForm("Socket Terminal", this);
		Vector methods = new Vector();
		methods.addElement("Direct");
		methods.addElement("Wait For Connection");
		myTerminalForm.presentActionChoices("How do you want to connect", methods);
		myTerminalForm.address.setLabel("IP Port separated by a space");
		if (myTerminalForm.getCurrentAddress().equals("Empty")){
			myTerminalForm.address.setString("111.111.111.111 9999");
		}
		Display.getDisplay(this).setCurrent(myTerminalForm.getDisplayable());

	}
	

	
	public void connectionMade(Connection _c, String _address) {
		_address = _address.substring(9,_address.length());
		_address = _address.replace(':',' ');
		myTerminalForm.put("Arrow Keys for 'Enter'");
		myTerminalForm.connectionMade(null, _address);
		Display.getDisplay(this).setCurrent(myTerminalForm.getDisplayable());
	}

	public void keyDown(int keyCode) {
		if (keyCode < 1){
			myConnection.send((byte) 13);
		}else{
			myConnection.send((byte) keyCode);
		}
	}
	public void madeChoice(int _which, String _choice) {
		if (_choice.equals("Wait For Connection")) {
			
		} else if (_choice.equals("Direct")) {
			String[] params = myTerminalForm.getParams();
			String ip = params[0];
			int port = Integer.parseInt(params[1]);
			//String directAddress = myTerminalForm.getCurrentAddress();
			//int space = directAddress.indexOf(" ");
			//String ip = directAddress.substring(0,space);
			//int port = Integer.parseInt(directAddress.substring(space+1, directAddress.length()));
			//myTerminalForm.put("direct connect" + ip + " " + port);
			initConnection(ip,port);
		} 
	}

	protected void pauseApp() {
		// TODO Auto-generated method stub
		
	}
	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
		// TODO Auto-generated method stub
		
	}

	public boolean madeMenuChoice(String _choice) {
		// TODO Auto-generated method stub
		return false;
	}

	public void incoming(Connection _c, byte[] _input) {
		myTerminalForm.incoming(_c,_input);
		
	}

	public void feedback(Connection _c, String _feedback) {
		myTerminalForm.feedback( _c, _feedback);
	}
*/
	
}
